package main

import (
	"fmt"
	"github.com/urfave/cli"
	"os"
	"runtime"
)

var commands = []cli.Command{
	{
		Name:   "new",
		Usage:  "fast create api service",
		Action: New,
	},
	{
		Name:  "api",
		Usage: "generate api related files",
		Flags: []cli.Flag{
			cli.StringFlag{
				Name:  "o",
				Usage: "the output api file",
			},
			cli.StringFlag{
				Name:  "dir",
				Usage: "the target dir",
			},
			cli.StringFlag{
				Name:  "new",
				Usage: "the api file",
			},
		},
		Action: Api,
		Subcommands:[]cli.Command{
			{
				Name:  "doc",
				Usage: "generate doc files",
				Flags: []cli.Flag{
					cli.StringFlag{
						Name:  "dir",
						Usage: "the target dir",
					},
					cli.StringFlag{
						Name:     "o",
						Required: false,
						Usage:    "the output markdown directory",
					},
				},
				Action: Doc,
			},
		},
	},
}

func main(){
	app := cli.NewApp()
	app.Usage = "a cli tool to generate code"
	app.Version = fmt.Sprintf("%s/%s",runtime.GOOS, runtime.GOARCH)
	app.Commands = commands
	// cli already print error messages
	if err := app.Run(os.Args); err != nil {
		os.Exit(1)
	}
}